#include "imcommon.h"

int analyse_fetion_sendfile(MsgNode * node)
{
/*
    <args><peers><uid>983176938</uid></peers><file id="
    9ECC5C0533F5EDE97894EC1ADC4688CE" size="64496" name="test.txt" is-expiration-valid="1">
    <chunk-list paged="FALSE"><chunk id="0" md5="4F6F6BDBC6E2D88853704D3135B445E3"/></chunk-list>
    </file></args>
 */
/*
 POST /cfp/postdata?s=1157283575/4732&sp=1&i=4F6F6BDBC6E2D88853704D3135B445E3&index=0&bp=0&ep=8192 HTTP/1.1
Content-Type: application/oct-stream
User-Agent: CloudFile v0.3
Host: 221.176.31.186
Content-Length: 8192
Cache-Control: no-cache

 */
    if (NULL == node->data)
        return -1;
    if (!strncmp(node->data, "POST /cfp/initializesession?", 28))
    {
        char *p = NULL;
        node->fileName = NULL;
        p = str_in_node(&node->fileName, 0, node->data, node->real_dataLen, "name=\"", "\"", 6, 0);
        if (NULL == p)
            return -1;
    }
    if (!strncmp(node->data, "POST /cfp/postdata?s=", 21))
    {
        char *p = NULL;
        char *tmplen = NULL;
        p = str_in_node(&tmplen, 0, node->data, node->real_dataLen,"\r\nContent-Length: ", "\r\n", 18, 0);
        if (NULL == p)
            return 0;
        node->filedataLen = atoi(tmplen);
        p = strstr(p, "\r\n\r\n");
        if (NULL == p)
            return 0;
        node->filedata = p+4;
    }
    else
        return 0;
    return 0;
}
